﻿
@{
    Layout = "ChinaMenu";
    Layout = "~/Views/Shared/_LayoutPageAll.cshtml";
    
}
@*页面中心内容*@
<div class="content clearfix">
    <div class="breadcrumbs">
        <h2 class="element-invisible">You are here</h2><div class="breadcrumb"><a href="/">返回主页</a> » 菜&nbsp;&nbsp;&nbsp;单 </div>
    </div>
    <div id="content" class="column content-inner">
        <div class="section">
            <a id="main-content"></a>
            <div class="region region-content">
                <div id="block-system-main" class="block block-system">
                    <div class="content">
                        <div class="product-menu-header">
                            <h2>Menu</h2>
                        </div>
                        @*菜单块*@
                        <div class="product-menu-holder">
                            <div id="dd" >
                                
                               
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="~/js/jquery-1.8.2.js"></script>

<script>
    $(document).ready(function () {

        var str = window.location.search;
        var index = str.lastIndexOf("=");
        var id = str.substr(index + 1);
    
        $.ajax({
           
            type: "Get", //访问WebService使用Post方式请求
 
            url: "http://localhost:19451/api/Menu/GetMenutype", 
            data: {id:id},          
            success: function (response) { //回调函数，result，返回值
            
                $(response).each(function (i, item) {
                    var tr = "";
                 
                    if (item.MenuId % 2 == 0) {
                        tr += "<div class='right-part'><h4><span class='text'>" + item.MenuName + "</span><span class='line'></span></h4><ul><li><div class='img-holder'><div class='canvas'></div><img typeof='foaf:Image' src='" + item.MenuPhoto + "' width='108' height'90' alt='' /></div><div class='price'><h5><a href='/product/convallis-sit-amet-tellus'>" + item.MenuName + "</a></h5><span>$" + item.MenuPrice + "</span></div><div class='description'><p>" + item.MenuDescrib + "</p></div><div class='form-actions form-wrapper' id='edit-actions--2'><input onclick='ADDCar(" + item.MenuId + ")'  class='node-add-to-cart form-submit' type='button' id='edit-submit-3' name='op' value='加入购物车' /></div></li></ul></div>"
                    }
                    else
                    {


                        tr += "<div class='left-part' ><h4><span class='text'>" + item.MenuName + "</span><span class='line'></span></h4><ul><li><div class='img-holder'><div class='canvas'></div><img typeof='foaf:Image' src='" + item.MenuPhoto + "' width='108' height'90' alt='' /></div><div class='price'><h5><a href='/product/convallis-sit-amet-tellus'>" + item.MenuName + "</a></h5><span>$" + item.MenuPrice + "</span></div><div class='description'><p>" + item.MenuDescrib + "</p></div><div class='form-actions form-wrapper' id='edit-actions--2'><input onclick='ADDCar(" + item.MenuId + ")' class='node-add-to-cart form-submit' type='button' id='edit-submit-3' name='op' value='加入购物车' /></div></li></ul></div>"
                    }

                    $("#dd").append(tr);
                }
                )
            }
        });
    }
)

    function ADDCar(n)
    {
        alert();
        var id=@Session["UserID"];
        $.ajax({
            type:'get',
            url:'http://localhost:19451/api/menu/GetMenuIdshow',
            data:{
                id:n,
            },
            success:function(data){
                if(data==""){
                    alert("");
                }
                else
                {
                    var arr=JSON.parse(data);
                    $(arr).each(function(i,obj){
                        $.ajax({
                            type: "Get", //访问WebService使用Post方式请求
                            url: "http://localhost:19451/api/menu/getaddcar",
                            data:{
                                CarId:obj.MenuId,
                                CarName:obj.MenuName,
                                CarPhoto:obj.MenuPhoto,
                                CarDescrib:obj.MenuDescrib,
                                CarPrice:obj.MenuPrice,
                                CarNum:1,
                                UserId:id,
                            },
                            success: function (response) { //回调函数，result，返回值

                          
                                if(response==1)
                                {
                                    alert('添加成功');
                                }
                                else if(response==2)
                                {
                                    alert('添加成功');
                                }
                                else
                                {                             
                                    alert('没有此菜品');
                                }
                            }
                        })

                    })


                }
            }
        })
        
    }


</script>